<div class="mws-panel grid_8">
    <div class="mws-panel-header">
        <span class="mws-i-24 i-table-1"><?= $this->pageHeading ?></span>
    </div>

    <div class="mws-panel-body">
        <div class="mws-panel-toolbar top clearfix ">
            <ul>
                <li><a class="mws-ic-16 ic-accept" href="<?= APPLICATION_URL_ADMIN ?>property/addattributes" title="Add">Add</a></li>
                <li><a class="mws-ic-16 ic-cross" href="javascript:void(0)" title="Delete" onclick="deleteitem()">Delete</a></li>
            </ul>
        </div>
        <!--<table class="mws-table">-->
        <table class="mws-datatable-fn mws-table">
            <thead>
                <tr>
                    <th width="2%"><input type="checkbox" name="deletebcchk" id="deletebcchk" onclick="return checkall(this)" /></th>
                    <th width="10%">Attribute Name</th>
                    <th width="3%">Status</th>
                    <th width="3%">Edit</th>
                </tr>
            </thead>
            <tbody>
                <?
                $i = 0;
                $j = 1;
                foreach ($this->arrData as $row) {
                    $start++;
                    $i++;

                    if ($row['attribute_status'] == 1) {
                        $image = 'tick.png';
                    } else {
                        $image = 'cross.png';
                    }
                    ?>
                    <tr class="gradeX">
                        <td style="text-align:center">
                            <input name='check<?= $j; ?>' id='check<?= $j; ?>' value='<?= $row['attribute_id']; ?>' 
                                   onchange='return check_check("bcdel", "deletebcchk")' type='checkbox'>
                            <script>
                                    $(document).ready(function(){
                                        $('#bcdel').html(''); 
                                        document.getElementById('deletebcchk').checked = false;
                                    });
                            </script>
                        </td>
                        <td><?= $row['attribute_name'] ?></td>
                        <td> <a id='<?= $start; ?>' onclick='changestatus("<?= $row['attribute_id']; ?>", "<?= $row['attribute_status']; ?>")' href="javascript:void(0)" >
                                <img src="<?= APPLICATION_URL_ADMIN; ?>css/icons/32/<?= $image; ?>"    border='0' height="16" width="16" title='Change Status' alt='Change Status'>
                            </a></td>
                        <td>
                            <a href="<?= APPLICATION_URL_ADMIN ?>property/editattribute/attrId/<?= $row['attribute_id'] ?>"><img src="<?= APPLICATION_URL_ADMIN; ?>css/icons/32/application_form_edit.png" height="16" width="16"   border='0' title='Edit' alt='Edit'></a>
                        </td>

                    </tr>
                    <?
                    $j++;
                }
                ?>
            </tbody>
        </table>
    </div>    	
</div>
<script>
                    function deleteitem()
                    {
                        var r = "";
                        var s = "";
                        var selected = false;
                        for (var i = 1; document.getElementById('check' + i); i++) {
                            if (document.getElementById('check' + i).checked == true) {
                                r += document.getElementById('check' + i).value + "|";
                                selected = true;
                            }
                        }

                        r += '0';
                        if (selected) {
                            var confirmation = confirm("Are you sure want to delete ?");
                            if (confirmation != true) {
                                return false;
                            }

                            $.ajax({url: "<?= APPLICATION_URL_ADMIN . "property/deleteattribute" ?>",
                                type: "POST",
                                async: false,
                                data: ({Id: r}),
                                success: function(data) {


                                    alert('Selected records have been deleted successfully.');

                                    window.location.href = window.location.href;
                                }});
                        } else {
                            alert('Please choose a record to delete.');
                        }
                    }


                    function checkall(thisid)
                    {
                        for (var i = 1; document.getElementById('check' + i); i++)
                        {
                            if (document.getElementById(thisid.id).checked == true) {
                                document.getElementById('check' + i).checked = true;
                            }
                            if (document.getElementById(thisid.id).checked == false) {
                                document.getElementById('check' + i).checked = false;
                            }
                        }
                    }

                    function changestatus(Id, Status)
                    {
                        $.ajax({
                            type: "POST",
                            url: "<?= APPLICATION_URL_ADMIN ?>property/changeattrstatus",
                            data: ({Id: Id, Status: Status}),
                            cache: false,
                            success: function(data) {
                                window.location.href = window.location.href;
                            }
                        });
                    }

</script>